<template>
	<view>
		<c-navBar :title="active===0?'每日反馈':active===1?'每月反馈':'阶段反馈'" :showAdd="false"></c-navBar>

		<component :is="getComponentItem" v-if="info" :info="info" @emitDate="emitDate"></component>
	</view>
</template>

<script setup>
	import {
		getTimeDate
	} from "@/utils/index.js"
	import {
		getFeedbackDayDetail,
		getFeedbackMonthDetail,
		getUserProgress,
	} from "@/apis/teachingFeedback.js"
	import componentOne from "./component/detailcomponent/feedbackday.vue"
	import componentTwo from "./component/detailcomponent/feedbackmonth.vue"
	import componentThree from "./component/detailcomponent/feedbackdayPlan.vue"
	import {
		ref,
		computed,
		reactive
	} from 'vue';
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app"

	const pramas = reactive({
		start_date: '',
		end_date: '',
	})
	const info = ref()
	const id = ref(0)
	const active = ref(0);
	onLoad((options) => {
		let time = getTimeDate()
		pramas.start_date = `${time.year}/${time.month}/${time.day}`
		pramas.end_date = `${time.year}/${time.month}/${time.day}`
		active.value = Number(options.type)
		id.value = Number(options.id)
		init()
	})
	const getComponentItem = computed(() => {
		switch (active.value) {
			case 0:
				return componentOne;
				break;
			case 1:
				return componentTwo;
				break;
			case 2:
				return componentThree;
				break;
		}
	})
	const emitDate = (e) => { 
		pramas.start_date = e.start_date
		pramas.end_date = e.end_date
		init()
		// console.log(e)
	}
	const init = async () => {
		try {



			if (active.value === 0) {
				let {
					data
				} = await getFeedbackDayDetail({
					id: id.value
				})

				if (data) {
					// console.log(data)
					info.value = data
				}
			} else if (active.value === 1) {
				let {
					data
				} = await getFeedbackMonthDetail({
					id: id.value
				})

				if (data) {
					info.value = data
				}
			} else {
				let {
					data
				} = await getUserProgress({
					start_date: pramas.start_date,
					end_date: pramas.end_date,
					id: id.value
				})

				if (data) {
					info.value = data
				}
			}


		} catch (err) {
			console.log(err)
		}



	}
</script>

<style lang="scss" scoped>


</style>